import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPopupMenu;

class PopupListener extends MouseAdapter {
	
	JPopupMenu fPopup = null;
	
	public void setPopup(JPopupMenu popup){
		fPopup = popup;
	}
  public void mousePressed(MouseEvent e) {
    maybeShowPopup(e);
  }

  public void mouseReleased(MouseEvent e) {
    maybeShowPopup(e);
  }

  private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
    	if( fPopup != null )
    		fPopup.show(e.getComponent(),
    								e.getX(), e.getY());
    }
  }
}